using net_work.Common.Request;
using net_work.Common.Result;
using net_work.Data.DTO.Sys;
using net_work.Data.Entity.Sys;
using net_work.IRepository.Sys;
using net_work.IService.Sys;

namespace net_work.Service.Sys;

public class PersonService(IPersonRepository personRepository) : IPersonService
{
    public Task<PagedResult<Person>> GetPeoplePagedAsync(PagedRequest request)
    {
        return personRepository.GetPagedAsync(request);
    }

    public Task<Person?> SelectByIdAsync(long personId)
    {
        return personRepository.GetByIdAsync(personId);
    }

    public async Task<long> InsertPerson(PersonAddRequest personAddRequest)
    {
        return await personRepository.InsertAsync(personAddRequest);
    }

    public async Task<int> UpdatePerson(PersonUpdateRequest personUpdateRequest)
    {
        if (personUpdateRequest.Id <= 0)
        {
            return -1;
        }

        return await personRepository.UpdateAsync(personUpdateRequest) ? 1 : -1;
    }

    public async Task<int> DeletePersonByIds(List<long> ids)
    {
        return await personRepository.DeleteByIdsAsync(ids) ? 1 : -1;
    }
}